package random

import (
	C "gitee.com/ljfirst/algo-go-sdk/common/constant"
	"math/rand"
)

/**
 * @author ljfirst
 * @version V1.0
 * @date 2023/7/19 13:47
 * @author-Email ljfirst@mail.ustc.edu.cn
 * @blogURL https://blog.csdn.net/ljfirst
 * @description 按照不同的概率生成 0 - 1
 **/
type NonEqualProbability struct {
}

// p 是 [0,100] 闭区间的 概率值
func (m *NonEqualProbability) NonEqualRandomMethod(p float64) int {
	randomNum := rand.Float64() * 100
	if randomNum < p {
		return 1
	}
	return 0
}

func (m *NonEqualProbability) GetAttribute() *C.Attribute {
	return &C.Attribute{
		Tags: []string{},
		Desc: &C.Desc{
			Name:        "RandomNonEqualProbability",
			NameCn:      "概率:按照不同的概率生成0-1",
			Description: "以概率p生成1，概率1-p生成0",
			ParamsDesc: map[string]string{
			},
			Example: map[int]string{
			},
		},
	}
}
